package com.cpi.cornpp.purchaseorder.converter;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;

import com.cpi.cornpp.purchaseorder.dto.PurchaseOrderCostVersionDTO;
import com.cpi.cornpp.purchaseorder.view.PurchaseOrderCostVersionView;

public class PurchaseOrderCostVersionConverter {
	public static PurchaseOrderCostVersionView convert(PurchaseOrderCostVersionDTO dto){
		PurchaseOrderCostVersionView view = null;
		
		if (dto != null){
			view = new PurchaseOrderCostVersionView();
			
			view.setCostElementId(dto.getCostElementId());
			view.setCostElementCode(dto.getCostElementCode());
			view.setPurchaseOrderVersionId(dto.getPurchaseOrderVersionId());
			view.setAmount(dto.getAmount());
		}
		
		return view;
	}
	
	public static PurchaseOrderCostVersionDTO convert(PurchaseOrderCostVersionView view){
		PurchaseOrderCostVersionDTO dto = null;
		
		if (view != null){
			dto = new PurchaseOrderCostVersionDTO();
			
			dto.setCostElementId(view.getCostElementId());
			dto.setPurchaseOrderVersionId(view.getPurchaseOrderVersionId());
			dto.setAmount(view.getAmount());
		}
		
		return dto;
	}
	
	public static List convertDTOList(List dtoList){
		List viewList = null;
		
		viewList = new ArrayList(0);
		
		if (CollectionUtils.isNotEmpty(dtoList)){
			
			for (Iterator itr = dtoList.iterator(); itr.hasNext(); ){
				viewList.add(convert((PurchaseOrderCostVersionDTO) itr.next()));
			}
		}
		
		return viewList;
	}
	
	public static List convertViewList(List viewList){
		List dtoList = null;
		
		dtoList = new ArrayList(0);
		
		if (CollectionUtils.isNotEmpty(viewList)){
			
			for (Iterator itr = viewList.iterator(); itr.hasNext(); ){
				dtoList.add(convert((PurchaseOrderCostVersionView) itr.next()));
			}
		}
		
		return dtoList;
	}
}